<?php
define('WATCH_SUCCESS', 'success');
define('WATCH_FAIL', 'fail');
/**
 *
 * User: guizheng@iflytek.com
 * Date: 2017/11/27 上午10:01
 */
class watcher_DNS {

    private $host_ips = array(
        'ai.xfyun.cn' => array(
            '117.121.50.210'
        ),
    );



    public function watch () {
        foreach ($this->host_ips as $host => $ips) {
            exec("ping $host -c 1",$info);
            foreach ($ips as $ip) {
                if (strpos($info[0], $ip)) {
                    return WATCH_SUCCESS;
                }
            }
            return WATCH_FAIL;
        }
    }
}

$watch = new watcher_DNS();
echo $watch->watch();